//
//  DKAuthProductSigleView.m
//  DanKU
//
//  Created by 蓝鳍互娱 on 2023/12/6.
//

#import "DKAuthProductSigleView.h"
@interface DKAuthProductSigleView()
@property (nonatomic, strong)UIView *dk_AuthHomeProductBgView;
@property (nonatomic, strong)UIImageView * dk_AuthHomeProductHeadImgView;
@property (nonatomic, strong)UILabel * dk_AuthHomeProductNameLab;
@property (nonatomic, strong)UILabel * dk_AuthHomeProductPriceLab;
@end
@implementation DKAuthProductSigleView
-(instancetype)init{
    self = [super init];
    if (self) {
        self.backgroundColor = UIColor.clearColor;
        self.layer.cornerRadius = DK_IsWidthScale(20);
        self.clipsToBounds = YES;
        [self creatSubView];
    }
    return self;
}
- (void)creatSubView{
    self.dk_AuthHomeProductBgView = [[UIView alloc] init];
    self.dk_AuthHomeProductBgView.alpha = 0.25;
    [self addSubview:self.dk_AuthHomeProductBgView];
    [self.dk_AuthHomeProductBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(-DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
    }];
    self.dk_AuthHomeProductHeadImgView = [[UIImageView alloc] init];
    self.dk_AuthHomeProductHeadImgView.userInteractionEnabled = YES;
    self.dk_AuthHomeProductHeadImgView.backgroundColor = UIColor.whiteColor;
    self.dk_AuthHomeProductHeadImgView.layer.cornerRadius = DK_IsWidthScale(19);
    self.dk_AuthHomeProductHeadImgView.clipsToBounds = YES;
    [self addSubview:self.dk_AuthHomeProductHeadImgView];
    [self.dk_AuthHomeProductHeadImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(@(DK_IsWidthScale(19)));
        make.width.equalTo(@(DK_IsWidthScale(38)));
        make.height.equalTo(@(DK_IsWidthScale(38)));
    }];
    self.dk_AuthHomeProductNameLab = [[UILabel alloc] init];
    self.dk_AuthHomeProductNameLab.font = DK_FONT_Regular(12);
    self.dk_AuthHomeProductNameLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.dk_AuthHomeProductNameLab];
    [self.dk_AuthHomeProductNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(self.dk_AuthHomeProductHeadImgView.mas_bottom).offset(DK_IsWidthScale(10));
        make.height.equalTo(@(DK_IsWidthScale(17)));
    }];
    self.dk_AuthHomeProductPriceLab = [[UILabel alloc] init];
    self.dk_AuthHomeProductPriceLab.font = DK_FONT_Regular(15);
    self.dk_AuthHomeProductPriceLab.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.dk_AuthHomeProductPriceLab];
    [self.dk_AuthHomeProductPriceLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(self.dk_AuthHomeProductNameLab.mas_bottom).offset(DK_IsWidthScale(8));
        make.height.equalTo(@(DK_IsWidthScale(21)));
    }];
    UIButton * dk_AuthHomeProductBtn = [[UIButton alloc] init];
    [dk_AuthHomeProductBtn addTarget:self action:@selector(selectHomeProduct) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dk_AuthHomeProductBtn];
    [dk_AuthHomeProductBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(@(DK_IsWidthScale(0)));
    }];
}
- (void)selectHomeProduct{
    if(self.SelectProductBlock){
        self.SelectProductBlock(self.dk_UserProductPackageMdl);
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    if(_productIndex == 1){
       CAGradientLayer *gradientLayer = [CAGradientLayer layer];
       gradientLayer.frame = self.dk_AuthHomeProductBgView.bounds;
       [self.dk_AuthHomeProductBgView.layer addSublayer:gradientLayer];
       gradientLayer.colors = @[(__bridge id)DK_Hex(@"#6CA7FF").CGColor, (__bridge id)DK_Hex(@"#3C8EFF").CGColor];
       gradientLayer.locations = @[@0.0,@1.0];
       gradientLayer.startPoint = CGPointMake(0.13, 0.13);
       gradientLayer.endPoint = CGPointMake(0.94, 0.94);
    }else if(_productIndex == 2){
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = self.dk_AuthHomeProductBgView.bounds;
        [self.dk_AuthHomeProductBgView.layer addSublayer:gradientLayer];
        gradientLayer.colors = @[(__bridge id)DK_Hex(@"#FF8A54").CGColor, (__bridge id)DK_Hex(@"#FF6325").CGColor];
        gradientLayer.locations = @[@0.0,@1.0];
        gradientLayer.startPoint = CGPointMake(0.13, 0.13);
        gradientLayer.endPoint = CGPointMake(0.94, 0.94);
    }else{
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.frame = self.dk_AuthHomeProductBgView.bounds;
        [self.dk_AuthHomeProductBgView.layer addSublayer:gradientLayer];
        gradientLayer.colors = @[(__bridge id)DK_Hex(@"#A6ACFF").CGColor, (__bridge id)DK_Hex(@"#6E86FF").CGColor];
        gradientLayer.locations = @[@0.0,@1.0];
        gradientLayer.startPoint = CGPointMake(0.13, 0.13);
        gradientLayer.endPoint = CGPointMake(0.94, 0.94);
    }
    [self.dk_AuthHomeProductBgView makeCornerOnTopleftRight:DK_IsWidthScale(100)];
}
-(void)setProductIndex:(NSInteger)productIndex{
    _productIndex = productIndex;
    if(_productIndex == 1){
        self.dk_AuthHomeProductNameLab.textColor = DK_Hex(@"#4566FF");
        self.dk_AuthHomeProductPriceLab.textColor = DK_Hex(@"#4566FF");
    }else if (_productIndex == 2){
        self.dk_AuthHomeProductNameLab.textColor = DK_Hex(@"#FF6A2D");
        self.dk_AuthHomeProductPriceLab.textColor = DK_Hex(@"#FF6A2D");
    }else{
        self.dk_AuthHomeProductNameLab.textColor = DK_Hex(@"#697FFF");
        self.dk_AuthHomeProductPriceLab.textColor = DK_Hex(@"#697FFF");
    }
}
-(void)setDk_UserProductPackageMdl:(DKUserProductPackageModel *)dk_UserProductPackageMdl{
    _dk_UserProductPackageMdl = dk_UserProductPackageMdl;
    if(_dk_UserProductPackageMdl){
        self.dk_AuthHomeProductNameLab.text = _dk_UserProductPackageMdl.name;
        self.dk_AuthHomeProductPriceLab.text = [NSString stringWithFormat:@"₹%@",[NSString makeShowMoney:_dk_UserProductPackageMdl.amount]];
        NSString *slogn = self.dk_UserProductPackMdl.slogan;
        NSDictionary *slognDic = [NSString stringChangeDic:slogn];
        NSString *slogan = [slognDic objectForKey:_dk_UserProductPackageMdl.id];
        
        self.dk_AuthHomeProductHeadImgView.image = [NSString imageWithBase64String:slogan];
    }
}
@end
